package com.hongxun.design.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hongxun.design.R;
import com.hongxun.design.bean.ExperienceBean;
import com.hongxun.design.utils.TimeUtil;
import com.hongxun.design.utils.imageutil.UriUtil;

import java.util.List;

/**
 * Created by zerdoor_pc on 2016/6/20.
 */
public class ExperienceAdapter extends BaseAdapter {
    Context context;
    List<ExperienceBean> itemBeans;
    LayoutInflater inflater;

    public ExperienceAdapter(Context context, List<ExperienceBean>itemBeans) {
        this.context = context;
        this.itemBeans = itemBeans;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return itemBeans.size();
    }

    @Override
    public Object getItem(int i) {
        return itemBeans.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holldler holldler = null;
        ExperienceBean bean= (ExperienceBean) getItem(i);
        if (view == null) {
            view = inflater.inflate(R.layout.listview_item_encyclopedias, null);
            holldler = new Holldler(view);
            view.setTag(holldler);
        } else {
            holldler = (Holldler) view.getTag();
        }

        try {
            holldler.name.setText(bean.title);
            holldler.image.setImageURI(UriUtil.getUri(bean.article_thumb));
            holldler.time.setText(TimeUtil.time(bean.create_time + "000"));
//            1000 待审核
//            1001 审核通过
//            1002 审核未通过
            String s="";
            switch (bean.audit_status){
                case "1000":
                    s="待审核";
                    holldler.right.setTextColor(context.getResources().getColor(R.color.login_yellow));
                    break;
                case "1001":
                    s="审核通过";
                    holldler.right.setTextColor(context.getResources().getColor(R.color.caikan_green));
                    break;
                case "1002":
                    s="审核未通过";
                    holldler.right.setTextColor(context.getResources().getColor(R.color.bar_left));
                    break;

            }
            holldler.right.setText(s);


        }catch (Exception e){

        }

        return view;
    }


    class Holldler {
        SimpleDraweeView image;
        RelativeLayout item;
        TextView right, name, time;

        Holldler(View v) {
            item = (RelativeLayout) v.findViewById(R.id.encyclopedias_item);
            image = (SimpleDraweeView) v.findViewById(R.id.encyclopedias_image);
            right = (TextView) v.findViewById(R.id.encyclopedias_right);
            name = (TextView) v.findViewById(R.id.encyclopedias_name);
            time = (TextView) v.findViewById(R.id.encyclopedias_time);
            //SetTypeface.set(right, IconSourse.RIGHTARROW);
             right.setTextSize(10);
        }
    }
}
